Mortgage Calculator

Use this JavaScript Applet to determine monthly mortgage payments.
Annual Percentage Rate: %

Amount of loan (in thousands):

Years of Loan:

Monthly Payments:

Total Cost of Loan:

Total Interest Paid:

Discussion

This applet shows more extensive use of formulas than the Tailor example. This mortgage calculator uses a compound interest equation to determine monthly payments over the life of a loan. Each piece of the equation is tightly coupled to the input form. The rate is recovered from the text input's value. The years and principle are calculated from the choices of the selection box. Simple arithmetic converts selection indices to mathematical values.

Please note: These payment numbers are not warranted, nor are they likely to be accurate.

Calculating payments:


function calculate(aform)
{
    // Recover the information from the form
    var totalPayments = (aform.YEARS.options.selectedIndex + 2) * 60
    var monthlyInterest = (parseFloat(aform.RATE.value) / 1200)
    var principle = (aform.PRINC.options.selectedIndex + 1)*10000
    
    // Compute the monthly payments using JavaScript math and
    // a standard compound interest formula
    var num = Math.pow(1 + monthlyInterest, totalPayments)    
    var monthly = principle * monthlyInterest * num / (num - 1)
    
    // Update the form
    aform.MONTHLY.value = "$"+stripDigits(monthly, 2)
    aform.TOTAL.value = "$" + stripDigits(monthly * totalPayments, 2)
    aform.INTEREST.value = "$" + stripDigits(monthly * totalPayments - principle, 2)
}
Copyright ©1998 by Charles River Media, All Rights Reserved